const searchTemplate = {
  product: {
    name: '产品名称%k%i',
    code: '600876',
    tags: [
      '开发申购',
      '开放赎回',
      '增强型指数基金'
    ]
  },
  research: {
    report: {
      name: '产品研究：%k%i',
      author: '杨冬庭',
      tags: [
        '行业',
        '行业策略报告'
      ],
      date: '5小时前'
    },
    chart: {
      name: '图%i：信创防护检查%k',
      desc: '资料来源：防护、检查快速增长，监管平台空间广阔',
      author: '郑武',
      date: '2021-10-22'
    },
    activity: {
      name: '产品研究：%k%i',
      timeStart: '2022-04-06 15:00:00',
      timeEnd: '2022-04-06 16:00:00',
      type: '电话会议',
      tags: [
        '研究',
        '无回放'
      ]
    },
    individuate: {
      name: '个股%k%i',
      code: '600876',
      levelChange: '谨慎增持',
      levelStatues: '',
      newPrice: '26.25',
      newPriceStatues: '',
      date: '2022-01-11'
    },
    collection: {
      name: '合集%k%i',
      desc: '元宇宙系列报告元宇宙系列报告元宇宙系列报告元宇宙系列报告元宇宙系列报告元宇宙系列报告元宇宙系列报告元宇宙系列报告元宇宙系列报告元宇宙系列报告元宇宙系列报告元宇宙系列报告元宇宙系列报告元宇宙系列报告元宇宙系列报告元宇宙系列报告元宇宙系列报告元宇宙系列报告',
      date: '2022-09-01'
    }
  },
  bond: {
    name: '债券%k%i',
    code: '600519.IB',
    profit: '1.83',
    leftTime: '2.1',
    interest: '2.23',
    publisher: '国家开发银行',
    rank: 'AAA',
    prop: '国有企业'
  },
  company: {
    manager: {
      name: '基金管理人%k%i',
      code: '600519.SZ',
      prop: '国有企业；证券公司',
      ceo: '杨玉成',
      rating: 'AAA',
      IssueBonds: '是',
      register: '5350000',
      fundNum: '10',
      sacle: '10',
      foundDate: '2015-10-21'
    },
    publisher: {
      name: '债券发行人%k%i',
      code: '600876',
      prop: '国有企业',
      rank: 'AAA',
      isIssue: '1',
      register: '432',
      foundDate: '2015-10-21'
    }
  },
  discover: {
    name: '发现%k%i',
    desc: '商品期权报价'
  }
};

const typeToCate = {
  all: [
    'product',
    'research.report',
    'research.chart',
    'research.activity',
    'research.individuate',
    'research.collection',
    'bond',
    'company.manager',
    'company.publisher',
    'discover'
  ],
  product: [
    'product'
  ],
  research: [
    'research.report',
    'research.chart',
    'research.activity',
    'research.individuate',
    'research.collection'
  ],
  bond: [
    'bond'
  ],
  company: [
    'company.manager',
    'company.publisher'
  ],
  discover: [
    'discover'
  ]
};

function getSearchOneCate (cate, keywords, count) {
  if (keywords.length === 0) return {};
  const cateArr = cate.split('.');
  const [cate1, cate2] = cateArr;
  const tpl = cate2 ? searchTemplate[cate1][cate2] : searchTemplate[cate1];
  const result = [];
  for (let i = 1; i < count + 1; i++) {
    const nameFormat = tpl.name.replace('%k', keywords).replace('%i', ('000000000' + i).slice(-4));
    result.push({
      ...tpl,
      name: nameFormat
    });
  }
  return result;
}

export function getSearch (type, keywords, count) {
  const cateList = typeToCate[type];
  const result = {};
  cateList.map(item => {
    result[item] = getSearchOneCate(item, keywords, count);
  });
  return result;
}
